<?php

class spRadioList extends spDiv
{
	public function __construct( $param=null )
	{
		parent::__construct( $param );
	
		if ( isset($param["items"]) && count($param["items"]) ) 
			$this->addItems( $param["items"] );
	}
	
	public function addItems( $items )
	{
		foreach ( $items as $i )
		{
			$this->addItem( $i );
		}
	}
	
	public function addItem( $item )
	{
		$name = isset($item["name"]) ? $item["name"]:"";
	
		$label =  new spLabel(array(
			"contentAfter" => $item["content"]
		));
	
		$input = new spInput(array(
			"name_id"	=> $item["value"],
			"type" 		=> "radio",
			"name" 		=> $name,
			"value" 	=> $item["value"]
		));
		
		$label->addChild( $input );
		parent::addChild( $label );
		parent::addChild( new spBreak );
	}
	
	public function selectItem( $s )
	{
		$checkbox = parent::find( $s );
		if ( $checkbox )
			$checkbox->addAttr( "checked", "checked" );	
	}
	
	public function setElementDataString( $s )
	{
		$this->selectItem( $s );
	}	
}


?>